{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d4484062-c495-4985-afa8-503a21a6a5a1",
   "metadata": {},
   "source": [
    "# Forecast Bands (Fan Chart)\n",
    "\n",
    "A fan chart (or forecast bands plot) shows a central forecast line with uncertainty ranges.\n",
    "This example uses standard deviation to simulate a confidence interval around a time-series trend."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "873d318f-e5d6-4c5a-b0a1-b5594a374622",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import hvplot.pandas  # noqa\n",
    "\n",
    "np.random.seed(1)\n",
    "dates = pd.date_range(\"2024-01-01\", periods=50, freq=\"D\")\n",
    "mean = np.cumsum(np.random.normal(0, 1, 50))\n",
    "std = np.linspace(1.0, 2.5, 50)\n",
    "df = pd.DataFrame({\n",
    "    'date': dates,\n",
    "    'mean': mean,\n",
    "    'upper': mean + std,\n",
    "    'lower': mean - std\n",
    "})\n",
    "\n",
    "band = df.hvplot.area(\n",
    "    x='date', y='lower', y2='upper', alpha=0.3,\n",
    "    color='gray', label='Uncertainty'\n",
    ")\n",
    "line = df.hvplot.line(x='date', y='mean', color='blue', label='Forecast')\n",
    "\n",
    "band * line"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9e20b324-370d-43f2-a651-2be16d599a09",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import hvplot.pandas  # noqa\n",
    "hvplot.extension('matplotlib')\n",
    "\n",
    "np.random.seed(1)\n",
    "dates = pd.date_range(\"2024-01-01\", periods=50, freq=\"D\")\n",
    "mean = np.cumsum(np.random.normal(0, 1, 50))\n",
    "std = np.linspace(1.0, 2.5, 50)\n",
    "df = pd.DataFrame({\n",
    "    'date': dates,\n",
    "    'mean': mean,\n",
    "    'upper': mean + std,\n",
    "    'lower': mean - std\n",
    "})\n",
    "\n",
    "band = df.hvplot.area(\n",
    "    x='date', y='lower', y2='upper', alpha=0.3,\n",
    "    color='gray', label='Uncertainty'\n",
    ")\n",
    "line = df.hvplot.line(x='date', y='mean', color='blue', label='Forecast')\n",
    "\n",
    "band * line"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f9f30649-68c7-4fc2-aab1-b9c52293d8ae",
   "metadata": {},
   "source": [
    ":::{seealso}\n",
    "- [Area Plots reference documentation](../../ref/api/manual/hvplot.hvPlot.area.ipynb).\n",
    "- [Line Plots reference documentation](../../ref/api/manual/hvplot.hvPlot.line.ipynb).\n",
    ":::"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
